package com.ruoyi.quartz.task;
import com.ruoyi.edu.domain.Paper;
import java.util.List;
import java.util.Arrays;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.ruoyi.edu.domain.Activity;
import com.ruoyi.edu.service.IActivityService;
import com.ruoyi.framework.message.Producer;
import com.ruoyi.framework.web.domain.server.Sys;
import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.edu.service.IPaperService;


@Component("eduTask")
public class EduTask {

    @Autowired
    private IActivityService activityService;
    @Autowired
    private IPaperService paperService;

    public void checkActivities() {
        StringBuilder sb = new StringBuilder("【通知】");
        for (Activity activity: activityService.selectIncompleteList()) {
            sb.append("社会活动记录'" + activity.getDetail() + "'未提供活动链接\n");
        }
        try {
            Producer.sendMessage(sb.toString());
        } catch (Exception e) {
            System.out.println("发送MQ消息异常");
        }
    }

    public void checkSubmittedPapers() {
        System.out.println("检查审核超时的记录并通过钉钉通知提醒");
        // 创建示例对象
        Paper example = new Paper();
        // 获取所有论文
        List<Paper> papers = paperService.selectAll(example);
        // 过滤并获取论文ID
        Long[] paperIds = papers.stream()
                .filter(paper -> paper.getStatus() == 1)
                .filter(paper -> Math.abs(System.currentTimeMillis() - paper.getSubmitTime().getTime()) > 24 * 60 * 60 * 1000)
                .map(Paper::getPaperId)
                .toArray(Long[]::new);
        // 打印论文ID列表
        System.out.println(Arrays.asList(paperIds));
        // 发送通知
        paperService.sendNotification(paperIds);
    }
}